<template>
    <div class="white-box">
        <title-more title="数据概览">
            <template #sub>
                <el-popover placement="right-start" title="" :width="700" trigger="hover">
                    <template #reference>
                        <el-icon color="#C1C1C1" :size="18"><QuestionFilled /></el-icon>
                    </template>
                    <template #default>
                        <p class="p-popover">注：实时数据仅供即时运营参考，最终以离线数据为准。</p>
                        <p class="p-popover">在线供应商：统计周期内，在线运营的供应商数</p>
                        <p class="p-popover">待审核供应商：统计周期内，待审核的供应商数</p>
                        <p class="p-popover">累计申请供应商：统计周期内，累计申请的供应商数</p>
                        <p class="p-popover">有成交供应商：统计周期内，在线运营且有下单成交的供应商数</p>
                    </template>
                </el-popover>
            </template>
        </title-more>
        <div class="data-prev flexs">
            <div class="data-prev__item">
                <div class="data-prev__tip">在线供应商</div>
                <p class="data-prev__nums">{{ objs.supp_online || "0" }}</p>
            </div>
            <div class="data-prev__item">
                <div class="data-prev__tip">待审核供应商</div>
                <p class="data-prev__nums">{{ objs.wait_supp || "0" }}</p>
            </div>
            <div class="data-prev__item">
                <div class="data-prev__tip">累计申请供应商</div>
                <p class="data-prev__nums">{{ objs.total_wait_supp || "0" }}</p>
            </div>
            <div class="data-prev__item">
                <div class="data-prev__tip">有成交供应商</div>
                <p class="data-prev__nums">{{ objs.supp_pay || "0" }}</p>
            </div>
        </div>
    </div>
    <div class="white-box">
        <title-more title="供应商排行榜"></title-more>
        <el-tabs v-model="tabName" type="card" @tab-click="handleTab">
            <el-tab-pane label="销量排行" name="0">
                <el-table
                    class="table-mb"
                    v-loading="loading"
                    :data="arr_data"
                    :header-cell-style="{ background: '#F5F7FA' }"
                    element-loading-background="rgba(255, 255, 255, 0.6)"
                >
                    <el-table-column label="排名" type="index" :index="indexMethod" width="120" />
                    <el-table-column label="供应商">
                        <template #default="{ row }">
                            <div class="table-lr">
                                <el-image class="table-lr__img img-mini" loading="lazy" :src="proxy.imgUrl + row.logo" fit="cover" v-if="row.logo" />
                                <div class="table-lr__right mini-right" :style="{ marginLeft: row.logo ? '10px' : '0' }">
                                    <p class="lr-user line-one">{{ row.title }}</p>
                                    <p class="lr-user">ID：{{ row.supplier_id }}</p>
                                </div>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column prop="product_sales" label="销量" />
                    <el-table-column prop="created_at_label" label="更新时间" />
                </el-table>
            </el-tab-pane>
            <el-tab-pane label="订单金额排行" name="1">
                <el-table
                    class="table-mb"
                    v-loading="loading"
                    :data="arr_data"
                    :header-cell-style="{ background: '#F5F7FA' }"
                    element-loading-background="rgba(255, 255, 255, 0.6)"
                >
                    <el-table-column label="排名" type="index" :index="indexMethod" width="120" />
                    <el-table-column label="供应商">
                        <template #default="{ row }">
                            <div class="table-lr">
                                <el-image class="table-lr__img img-mini" loading="lazy" :src="proxy.imgUrl + row.logo" fit="cover" v-if="row.logo" />
                                <div class="table-lr__right mini-right" :style="{ marginLeft: row.logo ? '10px' : '0' }">
                                    <p class="lr-user line-one">{{ row.title }}</p>
                                    <p class="lr-user">ID：{{ row.supplier_id }}</p>
                                </div>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column prop="total_money" label="订单金额（元）" />
                    <el-table-column prop="created_at_label" label="更新时间" />
                </el-table>
            </el-tab-pane>
            <el-tab-pane label="星级排行" name="2">
                <el-table
                    class="table-mb"
                    v-loading="loading"
                    :data="arr_data"
                    :header-cell-style="{ background: '#F5F7FA' }"
                    element-loading-background="rgba(255, 255, 255, 0.6)"
                >
                    <el-table-column label="排名" type="index" :index="indexMethod" width="120" />
                    <el-table-column label="供应商">
                        <template #default="{ row }">
                            <div class="table-lr">
                                <el-image class="table-lr__img img-mini" loading="lazy" :src="proxy.imgUrl + row.logo" fit="cover" v-if="row.logo" />
                                <div class="table-lr__right mini-right" :style="{ marginLeft: row.logo ? '10px' : '0' }">
                                    <p class="lr-user line-one">{{ row.title }}</p>
                                    <p class="lr-user">ID：{{ row.supplier_id }}</p>
                                </div>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column label="星级">
                        <template #default="{ row }"> {{ row.avg_score || 0 }} </template>
                    </el-table-column>
                    <el-table-column prop="created_at_label" label="更新时间" />
                </el-table>
            </el-tab-pane>
        </el-tabs>
        <el-pagination
            background
            v-model:current-page="page"
            v-model:page-size="pageSize"
            :page-sizes="pageSizeNum"
            :total="totalNums"
            layout="total, sizes, prev, pager, next, jumper"
        >
        </el-pagination>
    </div>
    <go-back />
</template>

<script setup>
import { getCurrentInstance, ref, onMounted, watch } from "vue"
import GoBack from "@components/GoBack.vue"
import { QuestionFilled } from "@element-plus/icons-vue"
import OneLoad from "@mixins/one-load"
import TitleMore from "@components/title-more.vue"

const { proxy } = getCurrentInstance()

onMounted(() => {
    getDataInfo()
})

// 概况
const objs = ref({
    supp_online: 0, // 在线供应商
    wait_supp: 0, // 待审核供应商
    total_wait_supp: 0, // 累计申请供应商
    supp_pay: 0, // 有成交供应商
})
function getDataInfo() {
    proxy.$axios
        .get("analyse/supplier/tongji")
        .then((res) => {
            if (res.data.code == 0) {
                let result = res.data.data
                objs.value.supp_online = result.supplier_total_count
                objs.value.wait_supp = result.supplier_wait_count
                objs.value.total_wait_supp = result.supplier_combine_count
                objs.value.supp_pay = result.supplier_pay_count
                getList()
            } else {
                proxy.$message({ message: res.data.msg, type: "error" })
            }
        })
        .catch((err) => {})
}

/**
 * minxin列表加载
 */
const { page, pageSizeNum, pageSize, loading, arr_data, totalNums, pubParams, pubRefreshParams, getdata } = OneLoad()

// 切换每页显示条数
watch(pageSize, (val) => {
    page.value = 1
    pubParams(getList)
})
// 跳转第几页
watch(page, (val) => {
    pubParams(getList)
})

const indexMethod = (index) => {
    return index + 1 + (page.value - 1) * pageSize.value
}
const tabsNav = ["sales", "money", "score"]
function getList() {
    let params = {
        page: page.value,
        limit: pageSize.value,
    }
    params.order = tabsNav[tabName.value]
    getdata("analyse/supplier/rank", params)
}

// tab切换
const tabName = ref("0")
const handleTab = (pane) => {
    tabName.value = pane.index
    pubRefreshParams(getList)
}
</script>
<script>
export default {
    name: "SupplierAnalytics",
}
</script>

<style lang="less" scoped>
.lr-user {
    margin-bottom: 0 !important;
}
.p-popover {
    font-size: @font-size-md;
    color: #595961;
    margin: @margin-xs 0px;
}
.data-prev {
    .data-prev__item {
        width: 24%;
        padding: @padding-mdl;
        overflow: hidden;
        border-radius: 10px;
        .data-prev__tip {
            margin-bottom: @margin-md;
            color: @gray-6;
        }
        .data-prev__nums {
            font-size: 26px;
            color: #111;
        }
        &:hover {
            background-color: #f4f8ff;
        }
        .data-prev__ratio {
            margin-top: @margin-base;
            color: @gray-6;
            .ratio-nums {
                color: @red;
                margin-left: -6px;
            }
        }
    }
}
:deep(.el-tabs) {
    .el-tabs__header {
        box-sizing: content-box;
    }
    .el-tabs__item {
        background: #f7f8fa;
        border-bottom: 1px solid #e4e7ed;
        &.is-active {
            color: #303133;
            background: #fff;
        }
    }
}
</style>
